#! /bin/sh

#---------------------------------------------------------------------
#                                init                                 
# 
# Create a project named by the --name argument.  The project
# should initially consist only of an empty directory,
# but that directory after initialization should be under
# version control so that, e.g., subsequent calls to add-dir,
# add-files, ignore-files, and remove-files can succeed.  (For version
# control systems that do not support in-place import, this might
# involve creating a temporary workspace).
#---------------------------------------------------------------------

#---------------------------------------------------------------------
#                           chicken and egg                           
#---------------------------------------------------------------------

test -f "${FW_ROOT}/share/fw/sh/fw-find.sh" && fws="${FW_ROOT}/share/fw/sh/fw-find.sh"
test -f "fw/sh/fw-find.sh" && fws="fw/sh/fw-find.sh"
test -f "fw.local/sh/fw-find.sh" && fws="fw.local/sh/fw-find.sh"
test ! -z "$fws" || {
  echo "revision/__REVISION_TYPE__/init: fatal: can't locate fw-find.sh" 1>&2
  exit 1
}

. "$fws"

#---------------------------------------------------------------------
#                              routines                               
#---------------------------------------------------------------------

fw_source "revision/__REVISION_TYPE__/init" "sh/fatal.sh"
fw_source "revision/__REVISION_TYPE__/init" "sh/parse-args.sh"
fw_source "revision/__REVISION_TYPE__/init" "sh/validate-args.sh"

#---------------------------------------------------------------------
#                                main                                 
#---------------------------------------------------------------------

parse_args "revision/__REVISION_TYPE__/init" "$@"

validate_args "revision/__REVISION_TYPE__/init" "name" ""

mkdir "$name"
